package com.mlick.dddk;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

import com.mlick.dddk.service.DKService;
import com.mlick.dddk.utils.CheckUtil;
import com.mlick.dddk.utils.DKUtils;
import com.mlick.dddk.utils.SysUtils;

public class MainActivity extends AppCompatActivity {

    //private TextView mTextMessage;

    private Button button;


    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.navigation_home:
                    //mTextMessage.setText(R.string.title_home);
                    return true;
                case R.id.navigation_dashboard:
                    //mTextMessage.setText(R.string.title_dashboard);
                    return true;
                case R.id.navigation_notifications:
                    //mTextMessage.setText(R.string.title_notifications);
                    return true;
            }
            return false;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //mTextMessage = findViewById(R.id.message);
        button = findViewById(R.id.buttonEnd);

        BottomNavigationView navigation = findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

        //SysUtils.out("===>是否有root权限" + RootCmd.haveRoot());

        startService(new Intent(this, DKService.class));


        boolean isCheck = CheckUtil.isServiceWorked(this, "com.mlick.dddk.service.DKService");
        SysUtils.out("服务是否启动" + isCheck);

        //TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        //imei = telephonyManager.getDeviceId();
        //
        //for (int slot = 0; slot < telephonyManager.getPhoneCount(); slot++) {
        //    imei = telephonyManager.getDeviceId(slot);
        //    if (!StringUtils.isEmpty(imei)) {
        //        break;
        //    }
        //}
    }


    public void runCmd(View v) {
        if (v.getId() == R.id.button) {
            //Toast.makeText(getApplicationContext(), "You Click It！", Toast.LENGTH_SHORT).show();
            DKUtils.rumProNewThread(1);
        }

        switch (v.getId()) {
            case R.id.button:
                DKUtils.rumProNewThread(1);
                break;
            case R.id.button2:
                DKUtils.rumProNewThread(2);
                break;
            case R.id.button3:
                DKUtils.rumProNewThread(3);
                break;
            case R.id.button4:
                DKUtils.rumProNewThread(4);
                break;
            case R.id.buttonEnd:
                boolean isCheck = CheckUtil.isServiceWorked(this, "com.mlick.dddk.service.DKService");
                SysUtils.out("服务是否启动" + isCheck);
                if (isCheck) {
                    button.setText("开始");
                    stopService(new Intent(this, DKService.class));
                } else {
                    button.setText("结束");
                    startService(new Intent(this, DKService.class));
                }
                //List<LogEntry> logEntries = DKApplication.liteOrm.query(new QueryBuilder<>(LogEntry.class).limit(0, 100).appendOrderDescBy("1"));
                //SysUtils.out("======" + logEntries.size());
                //
                //for (LogEntry logEntry : logEntries) {
                //    SysUtils.out("==========" + logEntry.toString());
                //}

                break;
        }
    }

}
